﻿using EntityStore.Enums;
using System.ComponentModel;
using System.Reflection;
using System.Text;

namespace EntityStore
{

    public class Style
    {
        [DisplayName("宽度"), Description("有效的值为: 100px  20% ")]
        public string? width { get; set; }

        [DisplayName("高度"), Description("有效的值为: 100px  20% ")]
        public string? height { get; set; }
        /// <summary>
        /// 定位方式,百分比 固定像素  文档定位
        /// </summary>
        public LocateMode LocateMode { get; set; } = LocateMode.Percentage;

        public int? widthWithScoll { get; set; }

        public int? heightWithScoll { get; set; }

        public int? topWithScoll { get; set; }

        public int? leftWithScoll { get; set; }

        [DisplayName("最小高度"), Description("有效的值为: 100px  20%,设定这个之后如果height小于这个,height失效")]
        public string? min_height { get; set; }
        [DisplayName("距离顶部"), Description("有效的值为: 100px  20% ")]
        public string? top { get; set; } = "0";
        [DisplayName("距离左边"), Description("有效的值为: 100px  20% ")]
        public string? left { get; set; } = "0";
        [DisplayName("背景色"), Description("点击前面按钮选择颜色,如果需要透明度,选择颜色后在后面输入00-FF之间的值")]
        public string? background_color { get; set; }
        [DisplayName("顺序"), Description("越大表示越在上面")]
        public int? z_index { get; set; } = 0;

        public Position? position { get; set; }


        /// <summary>
        /// 针对容器控件,是否显示水平滚动条
        /// </summary>
        public overflow? overflow_x { get; set; }
        /// <summary>
        /// 针对容器控件,是否显示垂直滚动条
        /// </summary>
        public overflow? overflow_y { get; set; }

        #region 边框


        public borderStyle? border_style { get; set; }
        public string? border_color { get; set; }
        public int? border_width { get; set; }
        //public string? border_top_style { get; set; }
        //public string? border_top_color { get; set; }
        //public int? border_top_width { get; set; }
        //public string? border_bottom_style { get; set; }
        //public string? border_bottom_color { get; set; }
        //public int? border_bottom_width { get; set; }
        //public string? border_left_style { get; set; }
        //public string? border_left_color { get; set; }
        //public int? border_left_width { get; set; }
        //public string? border_right_style { get; set; }
        //public string? border_right_color { get; set; }
        //public int? border_right_width { get; set; }
        #endregion
        public string OtherCss { get; set; }
        /// <summary>
        /// 生成
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            //if (!string.IsNullOrWhiteSpace(width))
            //{
            //    sb.Append(nameof(width) + ":" + width +";"); ;
            //}
            ////todo 为了性能,后续可以采用全手动拼接  2.在增加颜色属性值是否有效
            PropertyInfo[] properties = GetType().GetProperties();
            foreach (PropertyInfo property in properties)
            {
                string? value = property.GetValue(this)?.ToString();
                if (!string.IsNullOrWhiteSpace(value))
                {

                    if (property.Name == "OtherCss")
                    {
                        sb.Append(value + ";");
                    }
                    else if (property.Name== "border_width")
                    {
                        sb.Append(property.Name + ":" + value + "px;");
                    }
                    else if (property.Name == "top")
                    {
                        switch (LocateMode)
                        {
                            case LocateMode.Pixel:
                                sb.Append("top" + ":" + topWithScoll + "px;");
                                break;
                            case LocateMode.Percentage:
                                sb.Append("top" + ":" + (topWithScoll * 100 / heightWithScoll) + "%;");
                                break;
                            case LocateMode.Sticky:
                                break;
                            default:
                                break;
                        }

                    }
                    else if (property.Name == "left")
                    {
                        switch (LocateMode)
                        {
                            case LocateMode.Pixel:
                                sb.Append("left" + ":" + leftWithScoll + "px;");
                                break;
                            case LocateMode.Percentage:
                                sb.Append("left" + ":" + leftWithScoll * 100 / widthWithScoll + "%;");
                                break;
                            case LocateMode.Sticky:
                                break;
                            default:
                                break;
                        }

                    }
                    else if (property.Name == "widthWithScoll" || property.Name == "heightWithScoll" || property.Name == "topWithScoll" || property.Name == "leftWithScoll" || property.Name == "LocateMode")
                    {

                    }

                    else
                    {
                        sb.Append(property.Name + ":" + value + ";");
                    }
                }
            }
            return sb.ToString().Replace('_', '-');
        }
    }

    public enum overflow
    {
        //overflow-x
        [Description("自动")]
        auto,
        [Description("始终有")]
        scroll,
        [Description("内容可见")]
        visible,
        [Description("始终没有")]
        hidden,
        [Description("多余类容不显示")]
        clip,
        [Description("过时的属性")]
        overlay

    }
    public enum borderStyle
    {
        /// <summary>
        /// 圆点
        /// </summary>
        [Description("圆点")]dotted,
        /// <summary>
        /// 虚线
        /// </summary>
        [Description("虚线")] dashed,
        /// <summary>
        /// 实线
        /// </summary>
        [Description("实线")] solid,
        /// <summary>
        /// 双实线
        /// </summary>
        [Description("双实线")] @double,
        /// <summary>
        /// 无
        /// </summary>
        [Description("无边框")] none
    }
}
